package com.liao.work.ui.activity.game;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.liao.work.R;
import com.liao.work.util.SetActionBarTitle;

public class GameMora3Activity extends AppCompatActivity implements View.OnClickListener {

    private ImageView img_head;
    private TextView tv_win1;
    private Button btn;
    private TextView tv_win;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_game_mora3);
        SetActionBarTitle.setTitle(getSupportActionBar(), false, "猜拳游戏");
        initView();
        Intent intent = getIntent();
        String data = intent.getStringExtra("data");
        String data1 = intent.getStringExtra("data1");
        System.out.println();
        check(data1, data);
    }

    private void initView() {
        img_head = (ImageView) findViewById(R.id.img_head);
        tv_win1 = (TextView) findViewById(R.id.tv_win1);
        btn = (Button) findViewById(R.id.btn);
        tv_win = (TextView) findViewById(R.id.tv_win);

        btn.setOnClickListener(this);
    }

    private void check(String s, String s1) {
        String name;
        int image;
        String names;
        if (s.equals(s1)) {
            name = "平局";
            image = R.mipmap.draw;
            names = "平局了";
        } else {
            if (isWin(s, s1)) {
                name = "甲";
                image = R.mipmap.fial;
                names = "甲赢了";
            } else {
                name = "乙";
                image = R.mipmap.ok;
                names = "乙赢了";
            }
        }
        tv_win1.setText(name);
        tv_win.setText(names);
        img_head.setImageResource(image);
    }

    private boolean isWin(String s, String s1) {
        if (s.equals("剪刀") && s1.equals("布")) {
            return true;
        } else if (s.equals("石头") && s1.equals("剪刀")) {
            return true;
        } else if (s.equals("布") && s1.equals("石头")) {
            return true;
        }
        return false;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn:
                startActivity(new Intent(this, GameMoraActivity.class));
                finish();
                break;
        }
    }
}
